'use strict';
/**
 * 消息中心service
 */
app.service('InfocenterService', 
['$http', '$q', 'dialogs', 
function ($http, $q, dialogs) {
	var that = this;
	this.getGridOptions = function(){
		var _gridWidth = $(".panel-body").width();
        if(_gridWidth < 550){
        	_gridWidth = _gridWidth * 4;
        }
		var _columnWidth = (_gridWidth-40) / 4;
		return {
			//height: getGridHeight(),
			url: ISS.getPath('/message/list'),
			dataType: 'json',
			colModel : [
				    {display : 'ID',name : 'infoId',hide : 'true'},
				    {display : 'content',name : 'content',hide : 'true'},
				    {display : 'turnTo',name : 'turnTo',hide : 'true'},
                    {display : 'infocenter.title',name : 'title',width : _columnWidth * 1.4,process:function(value,index,item){
                    	return "<a ng-click='vm.showInfoDetail(" + index +")'>" + value + "</a>";
                    }},
                    {display : 'infocenter.type',name : 'infoType',width : _columnWidth,process:function(value,index,item){
                    	return value && value.infoTypeName;
                    }},
                    {display : 'infocenter.status',name : 'status',width : _columnWidth * 0.4,process:function(value,index,item){
                    	var desc = {0:"未读",1:"已读"};
                    	var style = {0:"",1:"style='color:green;'"};
                    	return "<span " + style[value] +"> "+ desc[value] +" </span>";
                    		
                    }},
                    {display : 'infocenter.date',name : 'updateTime',width : _columnWidth}
	        ],
			usepager: true,
	        showcheckbox: true,
	        pageMode:'jpa',
	        rp: 10,
			isDragCol: true
		};
	}
	//批量删除消息
	this.remove = function(data){
		return $http.post(
				ISS.getPath('/message/batchDelete'),
				data,
	            {contentType: 'json'}
				).then(function(resp){
					return resp.data;
				});
	}
	//消息设为已读
	this.setRead = function(id){
		return $http.patch(
				ISS.getPath('/message/' + id + '/read')
				).then(function(resp){
					return resp.data;
				});
	}
	
	this.queryMessageType = function(){
		return $http.patch(
				ISS.getPath('/infoType/getMessageType')
				).then(function(resp){
					return resp.data;
				});
	}
}]);